#pragma once
#include "lockqueue.h"
#include <string>

enum LogLevel{
    INFO,   // 普通信息
    ERROR,  // 错误信息
};

// Mprpc框架所需的日志系统
class Logger
{
public:
    void SetLogLevel(LogLevel level);   // 设置日志级别
    void Log(const std::string& msg);         // 写日志
    static Logger& GetInstance();       // 单例模式
private:
    Logger();
    Logger(const Logger&) = delete;
    Logger(Logger&&) = delete;
    Logger& operator=(const Logger&) = delete;

private:
    int m_loglevel;                     // 日志级别
    LockQueue<std::string> m_lckQue;    // 日志缓冲队列
};

// 定义写日志宏函数
#define LOG_INFO(logmsgformat, ...) \
    do                              \
    {                               \
        Logger& logger = Logger::GetInstance();         \
        logger.SetLogLevel(INFO);                       \
        char c[1024] = {0};                             \
        sprintf(c, 1024, logmsgformat, ##__VA_ARGS__);  \
        logger.Log(c);                                  \
    } while (0)

#define LOG_ERR(logmsgformat, ...)  \
    do                              \
    {                               \
        Logger& logger = Logger::GetInstance();         \
        logger.SetLogLevel(ERROR);                      \
        char c[1024] = {0};                             \
        sprintf(c, 1024, logmsgformat, ##__VA_ARGS__);  \
        logger.Log(c);                                  \
    } while (0)